package com.villaday.idf.custom.pop;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.Image;
import android.net.Uri;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.util.PopularUtil;
import com.villaday.idf.util.ToastUtil;

import razerdp.basepopup.BasePopupWindow;

import static android.content.Context.CLIPBOARD_SERVICE;

public class RefusePop extends BasePopupWindow {

    private Context mContext;
    private final TextView mTvCancel;
    private final TextView mTvPhone;
    private final TextView mTvTitle;
    private final TextView mTvContent;
    private final String mTitle;


    public RefusePop(final Context context, String title) {
        super(context);
        mContext = context;
        setBackground(0);
        setOutSideDismiss(true);
        setKeepSize(true);
        setPopupFadeEnable(false);
        setBackgroundColor(Color.parseColor("#B3000000"));
        setBlurBackgroundEnable(true);
//        findViewById(R.id.ll_refuse).startAnimation(PopularUtil.buildAnimal());

        mTitle = title;
        mTvTitle = findViewById(R.id.tv_refuse_title);
        mTvContent = findViewById(R.id.tv_refuse_content);
        ImageView ivRefuse = findViewById(R.id.iv_refuse);
        mTvCancel = findViewById(R.id.tv_refuse_cancel);
        mTvPhone = findViewById(R.id.tv_refuse_phone);

        LinearLayout llDelete = findViewById(R.id.ll_delete);
        LinearLayout llNormal = findViewById(R.id.ll_normal);
        TextView tvDeleteTitle = findViewById(R.id.tv_delete_title);
        TextView tvDeleteCancel = findViewById(R.id.tv_delete_cancel);
        TextView tvDeletePhone = findViewById(R.id.tv_delete_phone);


        switch (title) {
            case "拒单":
                mTvCancel.setVisibility(View.GONE);
                break;
            case "确认":
                ivRefuse.setBackgroundResource(R.drawable.ic_confirm);
                mTvTitle.setText("订单确认前\n请保证客人入住期间有房");
                mTvContent.setVisibility(View.GONE);
                mTvCancel.setText("取消");
                mTvPhone.setText("确认");
                break;
            case "删除":
                llDelete.setVisibility(View.VISIBLE);
                llNormal.setVisibility(View.GONE);
                tvDeleteCancel.setText("取消");
                break;
            case "直接关房":
                tvDeleteTitle.setText("确定要关闭所选日期的房态？");
                tvDeleteCancel.setText("取消");
                llDelete.setVisibility(View.VISIBLE);
                llNormal.setVisibility(View.GONE);
                break;
        }
        mTvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBtnClickListener.onBtnClick(v, mTitle.equals("确认") ? "订单取消" : mTvCancel.getText().toString());
            }
        });
        mTvPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBtnClickListener.onBtnClick(v, mTitle.equals("确认") ? "订单确认" : mTvPhone.getText().toString());
            }
        });


        tvDeleteCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        tvDeletePhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBtnClickListener.onBtnClick(v, " ");
                dismiss();
            }
        });


    }


    public void setChange(String title, String content, String cancel, String confirm) {
        mTvTitle.setText(title);
        mTvContent.setText(content);
        mTvCancel.setText(cancel);
        mTvPhone.setText(confirm);
    }

    OnBtnClickListener onBtnClickListener;

    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }

    public interface OnBtnClickListener {
        void onBtnClick(View view, String title);
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.popular_refuse);
    }

//
//    @Override
//    protected Animation onCreateShowAnimation() {
//        return PopularUtil.ShowAnimation();
//    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return PopularUtil.dismissAnimation();
    }
}
